home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’90 / Busy Box / Sources / heartbeat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-14  |  1.0 KB  |  59 lines  |  [TEXT/KAHL]

  1. /* file heartbeat.c
  2.     shows heartbeat-like indicator in its area
  3.     by LHL
  4. */
  5.  
  6. #include "busybox.h"
  7.  
  8. static int16 width, height, half;
  9. static Point whereLast;    /* what the last point drawn was    */
  10. Rect fooRect;
  11.  
  12. void InitHeartBeatObj(Rect *drawArea, int16 ID)
  13. {
  14.     fooRect = *drawArea;
  15.     width = fooRect.right - fooRect.left;
  16.     height = fooRect.bottom - fooRect.top;
  17.     half = height / 2;
  18.     SetRect(&fooRect, 0, 0, 500, 500);
  19.     
  20.     whereLast.h = 0;
  21.     whereLast.v = half;
  22.     
  23. }    /* InitHeartBeatObj    */
  24.  
  25.  
  26. void DrawHeartBeatObj(int16 ID)
  27. {
  28.     static int16    delta_vert, time_in;
  29.     
  30.     MoveTo(whereLast.h, whereLast.v);
  31.  
  32.     switch (time_in) {
  33.         case 1:
  34.             whereLast.v = half;
  35.             break;
  36.         case 2:
  37.             whereLast.v = whereLast.v - (half / 2);
  38.             break;
  39.         case 3:
  40.             whereLast.v  = whereLast.v +  half;
  41.             break;
  42.         case 4:
  43.             whereLast.v = whereLast.v - (half / 2);
  44.             break;
  45.     }
  46.     
  47.     if (++time_in > 4)
  48.         time_in = 0;
  49.  
  50.     if ((whereLast.h = whereLast.h + 8) > width) {
  51.         whereLast.h = 0;
  52.         EraseRect(&fooRect);
  53.         MoveTo(whereLast.h,whereLast.v);
  54.     }    
  55.  
  56.     LineTo(whereLast.h, whereLast.v);
  57.     
  58. }    /* DrawHeartBeatObj    */
  59.